<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="任务名称">
              <a-input v-model="queryParam.keyword" placeholder @keydown.enter="getDataList" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {
              this.pagination.current = 1
              this.getDataList()
            }">查询
            </a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = { Condition: 'Name' })">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-table ref="table" :scroll="{ y: tableHeight }" :columns="columns" :rowKey="(row, index) => row.Id"
      :dataSource="data" :pagination="pagination" :loading="loading" @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :bordered="true" size="small">
      <span slot="UserAvatarURL" slot-scope="text, record">
        <a v-if="hasPerm('Base_User.Edit')">
          <a-popover>
            <!-- <img :src="text" @error="this.src = null" width="30px" height="30px" /> -->
            <a-avatar icon="user" :src="text" style="width: 40px;height: 40px;" />
            <template #content>
              <a-avatar icon="user" :src="text" :size="200" style="width: 200px;height: 200px;" />
            </template>
          </a-popover>
        </a>
        <a v-if="!hasPerm('Base_User.Edit')">
          <a-popover>
            <!-- <img :src="text" @error="this.src = null" width="30px" height="30px" /> -->
            <a-avatar icon="user" :src="text" style="width: 30px;height: 30px;" />
            <template #content>
              <a-avatar icon="user" :src="text" :size="200" style="width: 200px;height: 200px;" />
            </template>
          </a-popover>
        </a>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <template v-if="hasPerm('Base_User.Edit')">
            <!-- <a-button type="link" ><a @click="handleEdit(record.Id)">巡检记录</a></a-button> -->
            <a @click="handleEdit(record.Id)">巡检记录</a>
            &nbsp;

          </template>
        </template>
      </span>
    </a-table>
    <Inspection ref="inspection" :pId="pId"></Inspection>
  </a-card>
</template>

<script>
import Inspection from './Inspection'  //巡检记录
const columns = [
  { title: '任务名称', dataIndex: 'Name', width: '30%' },
  { title: '应用名称', dataIndex: 'AppyName', width: '25%' },
  { title: '创建人', dataIndex: 'CreatorRealName', width: '25%' },
  {
    title: '创建日期', dataIndex: 'CreateTime', width: '22%', customRender: function (text) {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    }
  },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' }, width: '20%' }
]
export default {
  components: {
    Inspection
  },
  props: {
    pId: { require: true },
  },
  mounted() {
    this.$nextTick(() => {
      // 页面渲染完成后的回调
      this.tableHeight = this.getTableHeight(true) + 24
    })
    this.getDataList()
  },
  data() {
    return {
      tableHeight: 570, // 表格高度
      data: [],
      pagination: {
        current: 1,
        pageSize: 25,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['25', '50', '100'], // 设置pageSize的可选值，页面啊可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'CreateTime', order: 'desc' },
      loading: false,
      columns,
      queryParam: { Condition: 'Name' },
      selectedRowKeys: [],
      imgUrl: require('@/assets/logo.png')
    }
  },
  methods: {
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }

    },
    getDataList(id) {
      this.selectedRowKeys = []
      this.$http.post('/Base_TaskWork/Base_Task/GetTaskDataList', {
        PageIndex: this.pagination.current,
        PageRows: this.pagination.pageSize,
        SortField: this.sorter.field || 'Id',
        SortType: this.sorter.order,
        Search: { Condition: "ProjectId", Keyword: this.pId },
      }).then(resJson => {
        this.data = []
        setTimeout(() => {
          this.data = resJson.Data
        }, 1)
      })

    },

    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },

    handleEdit(id) {
      this.$refs.inspection.openForm(id, '巡检记录')
    },

  }
}
</script>
